
//store 单模块
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    count: 0,
    girl:{
        name:'',
        age:'',
        sex:''
    },
    boy:{
        girlName:'',
        jiji:''
        
    }
  },
  //提交事件
  mutations: {
    add (state) {
      state.count++
    },
    //传参数,这里的参数只能接收一个，多参数只能以对象传过来
    boy(state,boy){
        state.boy.girlName = boy.name
        state.boy.jiji = boy.diao;
       
    },
    girl(state,girl){
       
        state.girl.name = girl.name;
        state.girl.age = girl.age;
        state.girl.sex = girl.sex;
    }
    
  },
  //可以给对象赋值。 
  getters:{
      //传递参数
    girl: (state)=>(name,age,sex)=>{
        let girl = state.girl;
        girl.name = name;
        girl.age = age;
        girl.sex = sex;
        return  girl;
    }
  },
  //分发函数 
  actions:{
    girl(context,args){
        context.commit('girl',args)
    },
    boy(context,args){
        context.commit ('boy',args);
    }
  }
})
export default store